/**
 * Created by Administrator on 2016/12/1.
 */
define(['dojo/_base/declare', 'dojo/request', 'js/layer/Base', 'dojo/_base/lang'], function(declare, request, Base, lang) {
    return declare('js/layer/Vector', [Base], {
        createLayer: function(config) {
            var layer = new ol.layer.Vector({
                source: new ol.source.Vector({
                    //features: (new ol.format.GeoJSON()).readFeatures([])
                }),
                style: lang.hitch(this, this.styleFunction)
            });
            return layer;
        },
        initFeatures: function(config) {
        	var self = this;
            request(this.url, {handleAs: 'json'}).then(//使用配置文件在前端加载方式
                function(geoJson) {
                	//var geoJson = $.parseJSON(json);
                	self.getSource().addFeatures((new ol.format.GeoJSON()).readFeatures(geoJson));
                	//self.hideAllFeatures();
                },
                function (error) {
                    console.log(error ,self.type);
                }
            );
            //this.getSource().addFeatures((new ol.format.GeoJSON()).readFeatures(data));//后台数据库处理返回方式
//        	$.ajax({
//        		url: 'http://localhost:8090/geoserver/Map/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=Map:County&maxFeatures=50&outputFormat=application%2Fjson',
//        		type: 'get',
//        		dataType: 'json',
//        		success: function(json) {
//        			console.log(json);
//        			console.log(self);
//        		}
//        	});//用jquery请求方式
        },
        styleFunction: function(feature, resolution) {
        	if(feature.values_.hidden) return null;
        	switch(this.id) {
	        	case 'county':
	        		//console.log(feature);
	        		return [
	        		        	new ol.style.Style({
	        		        		fill: new ol.style.Fill({
	        		        			color: '#00bfff'
	        		        		}),
	        		        		stroke: new ol.style.Stroke({
	        		        			color: '#ffffff',
	        		        			width: 1
	        		        		})
	        		        	})
	        		        ];
	        	case 'cityBorder':
	        		return [
	        		        	new ol.style.Style({
	        		        		stroke: new ol.style.Stroke({
	        		        			color: '#000000',
	        		        			width: 2
	        		        		})
	        		        	})
	        		        ];
	        	case 'expressWay':
	        		return [
								new ol.style.Style({
									stroke: new ol.style.Stroke({
										color: '#C1A936',
										width: 3.5
									})
								}),
	        		        	new ol.style.Style({
	        		        		stroke: new ol.style.Stroke({
	        		        			color: '#FFDF46',
	        		        			width: 2
	        		        		})
	        		        	})
	        		        ];
	        	case 'countryRoad':
	        		return [
	        		        	new ol.style.Style({
	        		        		stroke: new ol.style.Stroke({
	        		        			color: 'rgb(241,220,161)',
	        		        			width: 2.5
	        		        		})
	        		        	}),
	        		        	new ol.style.Style({
	        		        		stroke: new ol.style.Stroke({
	        		        			color: 'rgb(252,232,172)',
	        		        			width: 1
	        		        		})
	        		        	})
	        		        ];
	        	case 'railWay':
	        		return [
	        		        	new ol.style.Style({
	        		        		stroke: new ol.style.Stroke({
	        		        			color: '#A1A1A1',
	        		        			width: 4
	        		        		})
	        		        	}),
	        		        	new ol.style.Style({
	        		        		stroke: new ol.style.Stroke({
	        		        			color: '#FFFFFF',
	        		        			width: 2.5
	        		        		})
	        		        	}),
	        		        	new ol.style.Style({
	        		        		stroke: new ol.style.Stroke({
	        		        			lineDash: [15,20],
	        		        			color: '#A1A1A1',
	        		        			width: 2
	        		        		})
	        		        	})
	        		        ];
	        	case 'countyLabel':
	        		return [
	        		        	new ol.style.Style({
	        		        		fill: null,
	        		        		stroke: null,
	        		        		text: new ol.style.Text({
	        		        			text: '123'
	        		        		})
	        		        	})
	        		        ]
        	}
        	
        }
    });
});